package _15_generics._15_2._15_2_3;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 持有一个特性类型的对象，列表，每次调用select 时，访问随机的一个
 */
public class RandomList<T> {

    private List<T> list = new ArrayList<T>();
    private Random random = new Random(47);

    public void add(T t){
        list.add(t);
    }
    public T select(){
        return list.get(random.nextInt(list.size()));
    }

    public static void main(String[] args) {
        RandomList<String> randomList = new RandomList<>();
        for (String s : "hello world sxc sf xxg xsfa sfsf sfwe".split(" ")){
            randomList.add(s);
        }
        for (int i =0 ; i<=10 ; i++){
            System.out.println(randomList.select() + " " + i);
        }

    }
}
